package com.yuyou.fn.timer.task;

import com.github.wens.mybatisplus.examples.Example;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import com.yuyou.fn.settlement.entity.MainAccount;
import com.yuyou.fn.settlement.service.IMainAccountService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 结算账户余额
 * Created by wens on 2017/4/26.
 */
@JobHander(value="SettleAccountTask")
@Component
public class SettleAccountTask extends IJobHandler {

    @Resource
    private IMainAccountService mainAccountService ;

    @Override
    public ReturnT<String> execute(String... params) throws Exception {

        //先结算业务组余额
        Example<MainAccount> example = MainAccount.createExample();
        example.createCriteria().andEqualTo("tag","busTeam");
        List<MainAccount> mainAccountList = mainAccountService.findListByExample(example);

        for(MainAccount mainAccount : mainAccountList ){
            mainAccountService.settleBalance(mainAccount);
        }

        example.clear();

        example.createCriteria().andIn("tag", Arrays.asList( "areaTeam","teacher"));
        mainAccountList = mainAccountService.findListByExample(example);

        for(MainAccount mainAccount : mainAccountList ){
            mainAccountService.settleBalance(mainAccount);
        }

        return ReturnT.SUCCESS ;


    }
}
